package com.test.common;

import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import msg.chestionar.ejb.bi.ChestionarBI;

import com.msg.chestionar.to.ChestionarTO;
import com.msg.chestionar.to.UtilizatorTO;

@ManagedBean(name = "userBean")
@RequestScoped
public class UserBean implements Serializable {

	private static final long serialVersionUID = -4759076671753497857L;

	private List<ChestionarTO> chestionare;

	@EJB
	private ChestionarBI chestionarBI;

	public String back() {
		return "user";
	}

	public List<ChestionarTO> getChestionare() {

		if (chestionare == null) {

			FacesContext context = FacesContext.getCurrentInstance();

			HttpSession session = (HttpSession) context.getExternalContext()
					.getSession(false);

			UtilizatorTO loggedInUser = (UtilizatorTO) session
					.getAttribute("loggedInUser");

			chestionare = chestionarBI.getChestionarPtrUser(loggedInUser
					.getId());
		}
		return chestionare;
	}

	public void setChestionare(List<ChestionarTO> chestionare) {
		this.chestionare = chestionare;
	}

	public String viewChestionar() {
		return "ch";
	}
}
